package com.github.dongglin.smart.spring.boot.plus.web.controller;

import com.github.dongglin.smart.spring.boot.plus.core.framework.pager.PageResult;
import com.github.dongglin.smart.spring.boot.plus.core.framework.response.ApiResponse;
import com.github.dongglin.smart.spring.boot.plus.web.dto.FormInfoAddDTO;
import com.github.dongglin.smart.spring.boot.plus.web.dto.FormInfoUpdateDTO;
import com.github.dongglin.smart.spring.boot.plus.web.req.FormInfoRequest;
import com.github.dongglin.smart.spring.boot.plus.web.resp.FormInfoDetailVo;
import com.github.dongglin.smart.spring.boot.plus.web.resp.FormInfoResponse;
import com.github.dongglin.smart.spring.boot.plus.web.service.FormInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *  控制器
 *
 * @author DongGL
 * @since 2023-09-20
 */
@Slf4j
@RestController
@RequestMapping("/web/forminfo")
@Tag(name = "")
@SuppressWarnings({"DuplicatedCode", "unused"})
public class FormInfoController {

    @Resource
    private FormInfoService formInfoService;

    /**
     * 添加
     *
     * @param formInfoAddDTO formInfoAddDTO
     * @return apiResponse
     * @throws Exception ex
     */
    @PostMapping("/addforminfo")
    @Operation(summary = "添加")
    public ApiResponse<Boolean> addFormInfo(@Valid @RequestBody FormInfoAddDTO formInfoAddDTO) throws Exception {
        return ApiResponse.result(formInfoService.addFormInfo(formInfoAddDTO));
    }

    /**
     * 修改
     *
     * @param formInfoUpdateDTO formInfoUpdateDTO
     * @return apiResponse
     * @throws Exception ex
     */
    @PostMapping("/updateforminfo")
    @Operation(summary = "修改")
    public ApiResponse<Boolean> updateFormInfo(@Valid @RequestBody FormInfoUpdateDTO formInfoUpdateDTO) throws Exception {
        return ApiResponse.result(formInfoService.updateFormInfo(formInfoUpdateDTO));
    }

    /**
     * 删除
     *
     * @param id id
     * @return ApiResponse
     * @throws Exception ex
     */
    @PostMapping("/deleteforminfo/{id}")
    @Operation(summary = "删除")
    public ApiResponse<Boolean> deleteFormInfo(@PathVariable Long id) throws Exception {
        return ApiResponse.result(formInfoService.deleteFormInfo(id));
    }

    /**
     * 获取详情
     *
     * @param id id
     * @return apiResponse
     * @throws Exception ex
     */
    @PostMapping("/getforminfoinfo/{id}")
    @Operation(summary = "详情")
    public ApiResponse<FormInfoDetailVo> getFormInfo(@PathVariable Long id) throws Exception {
        return ApiResponse.success(formInfoService.getFormInfoById(id));
    }

    /**
     * 分页列表
     *
     * @param formInfoRequest formInfoRequest
     * @return apiResponse
     * @throws Exception ex
     */
    @PostMapping("/getforminfopage")
    @Operation(summary = "分页列表")
    public ApiResponse<PageResult<FormInfoResponse>> getFormInfoList(@Valid @RequestBody FormInfoRequest formInfoRequest) throws Exception {
        return ApiResponse.success(formInfoService.getFormInfoPagerList(formInfoRequest));
    }

}
